import pandas as pd
import matplotlib.pylab as plt
import seaborn as sns
%matplotlib inline
plt.style.use(['seaborn-dark']) # bmh Styling used for Visulization
df = pd.read_csv("Average Temperature of Cities.csv")
print ('Data read into a pandas dataframe!')
Data read into a pandas dataframe!
df.head() #Calling first 5 rows
City | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | London | 4.8 | 4.9 | 6.7 | 9.4 | 12.7 | 15.7 | 17.8 | 17.3 | 15.0 | 11.8 | 7.8 | 5.3 |
1 | Paris | 4.3 | 4.6 | 7.4 | 10.7 | 14.3 | 17.7 | 19.8 | 19.4 | 16.4 | 12.6 | 7.9 | 4.8 |
2 | NewYork | -1.0 | 0.0 | 4.1 | 10.4 | 16.0 | 21.3 | 24.5 | 23.6 | 20.1 | 13.7 | 7.7 | 2.5 |
table = pd.pivot_table(data=df,index='City')
table = table.reindex(columns=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'])
table.head()
Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
City | ||||||||||||
London | 4.8 | 4.9 | 6.7 | 9.4 | 12.7 | 15.7 | 17.8 | 17.3 | 15.0 | 11.8 | 7.8 | 5.3 |
NewYork | -1.0 | 0.0 | 4.1 | 10.4 | 16.0 | 21.3 | 24.5 | 23.6 | 20.1 | 13.7 | 7.7 | 2.5 |
Paris | 4.3 | 4.6 | 7.4 | 10.7 | 14.3 | 17.7 | 19.8 | 19.4 | 16.4 | 12.6 | 7.9 | 4.8 |
sns.set(rc = {'figure.figsize':(12,8)})
grid_kws = {"height_ratios": (.9, .05), "hspace": .3}
f, (ax, cbar_ax) = plt.subplots(2, gridspec_kw=grid_kws)
ax = sns.heatmap(table, ax=ax,cmap='seismic', annot=True,
cbar_ax=cbar_ax,
cbar_kws={"orientation": "horizontal"})
ax.set_title('Average Temperature of Cities', fontdict={'fontsize':18}, pad=12)
Text(0.5, 1.0, 'Average Temperature of Cities')
from pandas.plotting import parallel_coordinates
plt.figure(figsize = (12,8))
plt.title("Parallel Coordinates of Cities",fontsize = 18)
plt.xlabel("Month",fontsize = 14)
plt.ylabel("Temperature",fontsize = 14)
parallel_coordinates(df,'City',color=['blue','green','red'])
plt.show()
import folium
#fig2=Figure(width=550,height=350)
m2=folium.Map(location=[51.50585,-0.08580],zoom_start=15)
folium.TileLayer('Stamen Terrain').add_to(m2)
folium.TileLayer('Stamen Toner').add_to(m2)
folium.TileLayer('Stamen Water Color').add_to(m2)
folium.TileLayer('cartodbpositron').add_to(m2)
folium.TileLayer('cartodbdark_matter').add_to(m2)
folium.LayerControl().add_to(m2)
folium.Marker(location=[51.505852073619344, -0.08580355285735251],popup='London Bridge Bus Station (Stop A)',tooltip='Stop A').add_to(m2)
folium.Marker(location=[51.505184268753986, -0.08763818379407412],popup='London Bridge Bus Station (Stop D)',tooltip='Stop D').add_to(m2)
folium.Marker(location=[51.506112514864014, -0.08698372480495119],popup='London Bridge Bus Station (Stop R)',tooltip='Stop R').add_to(m2)
folium.Marker(location=[51.50685376256651, -0.08800296421424098],popup='London Bridge Bus Station (Stop Y)',tooltip='Stop Y').add_to(m2)
loc = [(51.505852073619344, -0.08580355285735251),
(51.505184268753986, -0.08763818379407412),(51.506112514864014, -0.08698372480495119)]
loc2 = [(51.505852073619344, -0.08580355285735251),
(51.506112514864014, -0.08698372480495119),(51.50685376256651, -0.08800296421424098)]
loc3 = [(51.50685376256651, -0.08800296421424098),
(51.505184268753986, -0.08763818379407412),(51.506112514864014, -0.08698372480495119)]
folium.PolyLine(loc,
color='red',
weight=4,
opacity=0.8).add_to(m2)
folium.PolyLine(loc2,
color='Green',
weight=2,
opacity=0.8).add_to(m2)
folium.PolyLine(loc3,
color='blue',
weight=2,
opacity=0.8).add_to(m2)
m2